<template>
    <swiper :options="swiperOption">
      <!-- slides -->
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div class="icons-box">
          <div v-for="item in page" :key="item.id">
            <img :src="item.imgUrl">
            <p>{{item.desc}}</p>
          </div>
        </div>
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
</template>

<script>
export default {
  name: 'Icons',
  data () {
    return {
      swiperOption: {
        // 循环轮播
        loop: false
      }
    }
  },
  props: ['iconList'],
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  .icons-box
    width: 100%
    display flex
    flex-wrap wrap
    text-align center
  .icons-box > div
    box-sizing border-box
    width: 25%
    padding: .3rem
    padding-bottom:0
  .icons-box > div > img
    width: 100%
  .icons-box > div > p
    padding-top:.2rem
    white-space nowrap
</style>
